package sort;

/**
 * @author Europa
 * @create 2020-05-15 1:19
 */
public class Selection extends Sort {

    /**
     * 选择排序<br/>
     * 可视化 https://www.bilibili.com/video/BV1RJ41167sB
     * @param array int数组
     */
    @Override
    public void sort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            // 最小值的索引
            int min = i;
            for (int j = i + 1; j < array.length; j++) {
                if (less(array[j], array[min])) {
                    min = j;
                }
            }
            exchange(array, i, min);
        }
    }
}
